package com.example.mapper;

import com.example.pojo.Attraction;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;

@Mapper
public interface AttractionMapper {

    @Select("select " +
            "a.id, " +
            "a.name, " +
            // 直接关联详情表，取第一条图片（用LIMIT 1确保唯一）
            "(select src from attraction_detail where attraction_id = a.id limit 1) as src, " +
            "a.remark, " +
            // 直接关联地址表取名称
            "addr.content as addressName, " +
            // 本周访客量（来自周表）
            "vw.count as visitorTotal " +
            "from attraction a " +
            // 关联地址表
            "left join address addr on a.address_id = addr.id " +
            // 关联周访客表
            "left join visitor_week vw on a.id = vw.attraction_id " +
            // 按本周访客量降序，取前9
            "order by vw.count desc " +
            "limit 9")
    List<Attraction> selectTop9ByVisitor();
}